package com.guigu.www.luolujin.Service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guigu.www.luolujin.Service.LljTemplateFoodService;
import com.guigu.www.mapper.TemplateFoodMapper;
import com.guigu.www.pojo.PageVo;
import com.guigu.www.pojo.TemplateFood;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 作者 罗露金
 */
@Service
public class LljTemplateFoodServiceImpl implements LljTemplateFoodService {
    @Autowired
    TemplateFoodMapper mapper;
    @Override
    public PageVo<TemplateFood> pageTemFood(Integer pageNum, Integer pageSize, String tempFoodName) {
        QueryWrapper<TemplateFood> wrapper = new QueryWrapper<>();
        wrapper.like("temp_food_name",tempFoodName);
        Page page = new Page(pageNum, pageSize);
        IPage iPage = mapper.selectPage(page, wrapper);
        PageVo<TemplateFood> templateFoodPageVo = new PageVo<>();
        templateFoodPageVo.setRows(iPage.getRecords());
        templateFoodPageVo.setTotal(iPage.getTotal());
        return templateFoodPageVo;
    }

    @Override
    public void insertTemFood(TemplateFood templateFood) {
        mapper.insert(templateFood);
    }

    @Override
    public void updateTemFood(TemplateFood templateFood) {
        mapper.updateById(templateFood);
    }

    @Override
    public void deleteTemFood(int tempFoodId) {
        mapper.deleteById(tempFoodId);
    }

    @Override
    public List<TemplateFood> queryById(int foodZongId) {
        return mapper.queryById(foodZongId);
    }

    @Override
    public TemplateFood selectById(int tempFoodId) {
        return mapper.selectById(tempFoodId);
    }

    @Override
    public void upTemFood(Integer tempFoodId, Integer tempFoodState) {
        TemplateFood templateFood = new TemplateFood();
        templateFood.setTempFoodId(tempFoodId);
        templateFood.setTempFoodState(tempFoodState);
        mapper.updateById(templateFood);
    }
}
